﻿using CCWin.Win32.Const;
using ERP_SaaS_WinForm.登录.Model;
using ERP_SaaS_WinForm.采购管理.Server;
using ERP_SaaS_WinForm.销售;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Net.Mail;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ERP_SaaS_WinForm.登录
{
    public partial class UpdateProductInspact : Form
    {
        public string btn = "";
        public UpdateProductInspact()
        {

            InitializeComponent();
       
        }
        
  
        public int id = 0;
        public HttpClient client = new HttpClient();
        private int ClientId = 1; // 当前页码

        private int totalPages; // 总页数

        public async void FirstValue()
        {
            string url = "http://10.223.8.3:8077/api/ProductIntory/FirstProductInspection";
            string requestUrl = $"{url}?id={id}";
            HttpResponseMessage response = await client.GetAsync(requestUrl);
            string json = await response.Content.ReadAsStringAsync();

            // 反序列化为ApiPaging<T>（假设T是List<YourModel>）
            var apiPaging = JsonConvert.DeserializeObject<ApiPaging<List<ProductInspection>>>(json);
            // 绑定数据到DataGridView
            textBoxName.Text = apiPaging.data[0].InspectionItemName.ToString();
            textBoxCode.Text = apiPaging.data[0].InspectionItemCode.ToString();
            textBoxhg.Text = apiPaging.data[0].ErrorUpperLimit.ToString();
            textBoxbhg.Text = apiPaging.data[0].ErrorLowerLimit.ToString();
            textBoxcheck.Text = apiPaging.data[0].MinorDefect.ToString();
            textBoxresult.Text = apiPaging.data[0].CriticalDefect.ToString();
            textBoxMark.Text = apiPaging.data[0].Remark.ToString();
        }
        private void UpName_Click(object sender, EventArgs e)
        {

        }
        ProductInspection ProductInspection = new ProductInspection();

        private async Task<int> GetClientId(int id)
        {
            return 1;
        }
        public async void ShowData() 
        {
            string ShowUrl = "";
            string ReponseUrl = $"{ShowUrl}";
            HttpResponseMessage reponse = await client.GetAsync(ReponseUrl);
            string json=await reponse.Content.ReadAsStringAsync();
            ApiResponse<CheckProductWork> result = JsonConvert.DeserializeObject<ApiResponse<CheckProductWork>>(json);
            List<CheckProductWork> datas=result.data;
            Checkdataview.DataSource = datas;


        }
        private void btnup_Click(object sender, EventArgs e)
        {
            ShowData();
        }

        private void UpdateProductInspact_Load(object sender, EventArgs e)
        {
            if (btn == "添加")
            {
                btnup.Text = btn;
            }
            else
            {
                btnup.Text = "编辑";
                FirstValue();
            }
         
        }

        private void Checkdataview_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
          
        }
   
        private void txtadd_Click(object sender, EventArgs e)
        {
            var procurementForm = new ERP_SaaS_WinForm.登录.AddCheckWork();
            procurementForm.Show();
        }
    }
}
